package p.ithorns.example.statemachine.test;

import p.ithorns.example.statemachine.core.StateEnum;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * FlowStatus
 * 流程状态
 *
 * @author ithorns
 * @version 1.0.0
 * @date 2022/10/1 21:52
 */
public enum FlowStatus implements StateEnum {

    // 无
    NONE(0),

    // 创建
    CREATED(1),

    // 待审批
    APPROVING(2),

    // 待接收
    RECEIVING(3),

    // 已接收
    RECEIVED(4),

    // 已指派
    ASSIGNED(5),

    // 完结
    COMPLETED(6),

    // 评价
    EVALUATED(7),

    ;

    private final int order;

    FlowStatus(int order) {
        this.order = order;
    }

    public int order() {
        return order;
    }

    private final static Map<Integer, FlowStatus> MAP =
            Arrays.stream(FlowStatus.values()).collect(Collectors.toMap(FlowStatus::order, v -> v));

    public static FlowStatus of(Integer status) {
        if (null == status) {
            return NONE;
        }
        return Optional.ofNullable(MAP.get(status))
                .orElse(NONE);
    }

    @Override
    public String getCode() {
        return this.name();
    }

}